using MicroMsg.Common.Algorithm;
using MicroMsg.Common.Timer;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Network;
using MicroMsg.Storage;
using Microsoft.Phone;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
namespace MicroMsg.Plugin.Sns.Scene
{
	public class SnsPostService : IStorageLogin
	{
		private const string TAG = "SnsPostService";
		private const string JPEG_POSTFIX = ".jpg";
		private const int MAX_RUNNING = 5;
		public const uint MM_SYNC_TO_WEIBO = 1u;
		public const uint MM_SYNC_TO_FACEBOOK = 2u;
		private static IsolatedStorageFile mCurrentIsolatedStorage = null;
		public static int mMaxCountOnce = 3;
		public static bool isBeenLogout = false;
		public static SnsPostService instance = null;
		private static TimerObject mTimerObject = null;
		private static void init()
		{
			if (SnsPostService.instance == null)
			{
				SnsPostService.instance = new SnsPostService();
				StorageBasic.registerLoginNotify(SnsPostService.instance);
			}
		}
		public void onLogout()
		{
			SnsPostService.isBeenLogout = true;
		}
		public void onLogin(string userName)
		{
			SnsPostService.isBeenLogout = false;
		}
		public static bool shareToTimeLine(SnsInfo snsObj)
		{
			return snsObj != null && snsObj.bytesObjectDesc != null && new NetSceneSnsPost().doScene(snsObj);
		}
		private static bool UploadAndPostEx(SnsInfo snsObject, string words, uint syncFlag, int privacy, SnsObjectType type, BgImgType bgImgType)
		{
			if (snsObject == null)
			{
				return false;
			}
			SnsPostContext snsPostContext = new SnsPostContext();
			snsPostContext.strContent = words;
			snsPostContext.localSnsObject = snsObject;
			snsPostContext.sync2WeiboFlag = syncFlag;
			snsPostContext.privacyFlag = privacy;
			snsPostContext.bgImgType = bgImgType;
			snsPostContext.objectType = (int)type;
			if (type == SnsObjectType.MMSNS_OBJECT_TEXT)
			{
				NetSceneSnsPost netSceneSnsPost = new NetSceneSnsPost();
				netSceneSnsPost.doScene(snsPostContext);
				return true;
			}
			if (!snsPostContext.initSnsTransContext())
			{
				Log.smethod_1("SnsPostService", "initSnsTransContext fail!");
				snsPostContext.mSnsObjectStatus = 5;
				return false;
			}
			SnsPostContextMgr.getInstance().putToHead(snsPostContext);
			SnsPostService.checkReadyContextDispatcher();
			return true;
		}
		public static bool UploadAndPost(List<TloMedia> mediaList, List<string> userNameList, TloLocation location, string words, uint syncFlag, int privacy, SnsObjectType type, BgImgType bgImgType = BgImgType.MMSNS_SETBGIMG_SELFPIC, List<ulong> groupIdList = null)
		{
			SnsPostService.init();
			if (type == SnsObjectType.MMSNS_OBJECT_PHOTO && (mediaList == null || mediaList.get_Count() <= 0))
			{
				return false;
			}
			if (words == null)
			{
				words = "";
			}
			Log.smethod_5("SnsPostService", "Begin UploadAndPost");
			List<TloMedia> list = new List<TloMedia>();
			if (mediaList != null)
			{
				using (List<TloMedia>.Enumerator enumerator = mediaList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						TloMedia current = enumerator.get_Current();
						TloMedia tloMedia = SnsPostService.rotatePicture(current);
						if (tloMedia != null)
						{
							list.Add(tloMedia);
						}
					}
				}
			}
			SnsInfo snsObject = SnsPostService.createLocalSnsObject(list, userNameList, location, words, privacy, type, groupIdList);
			SnsPostService.UploadAndPostEx(snsObject, words, syncFlag, privacy, type, bgImgType);
			if (type == SnsObjectType.MMSNS_OBJECT_BACKGROUND && list != null && list.get_Count() != 0)
			{
				AccountMgr.getCurAccount().strSnsBGImgID = list.get_Item(0).strUrl;
			}
			return true;
		}
		private static TloMedia rotatePicture(TloMedia media)
		{
			if (media == null)
			{
				return null;
			}
			if (media.mPicture == null && string.IsNullOrEmpty(media.strUrl))
			{
				return null;
			}
			if (SnsMediaStorage.isHttp(media.strUrl))
			{
				return media;
			}
			Stream stream = null;
			if (media.mPicture == null)
			{
				byte[] array = StorageIO.readFromFile(media.strUrl);
				if (array != null)
				{
					stream = new MemoryStream(array);
				}
			}
			else
			{
				stream = media.mPicture.GetImage();
			}
			if (stream == null)
			{
				return null;
			}
			int num = media.nAngle % 360;
			TloMedia result;
			if (num > 0)
			{
				int int_ = (int)stream.get_Length();
				WriteableBitmap writeableBitmap = PictureDecoder.DecodeJpeg(stream);
				if (writeableBitmap == null)
				{
					return null;
				}
				WriteableBitmap writeableBitmap2 = Util.rotatePicture(writeableBitmap, num);
				if (writeableBitmap2 != null)
				{
					result = SnsPostService.snsSavePhotoEx(writeableBitmap2, int_, true, true);
				}
				else
				{
					result = SnsPostService.snsSavePhoto(stream, true, true);
				}
			}
			else
			{
				result = SnsPostService.snsSavePhoto(stream, true, true);
			}
			return result;
		}
		public static void delTmpMedia(List<TloMedia> mediaList)
		{
			using (List<TloMedia>.Enumerator enumerator = mediaList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					TloMedia current = enumerator.get_Current();
					if (current != null && !string.IsNullOrEmpty(current.strUrl) && !string.IsNullOrEmpty(current.strThumb))
					{
						StorageIO.deleteFile(current.strUrl);
						StorageIO.deleteFile(current.strThumb);
					}
				}
			}
		}
		private static SnsInfo createLocalSnsObject(List<TloMedia> mediaList, List<string> userNameList, TloLocation location, string words, int Privacy, SnsObjectType type, List<ulong> groupIdList)
		{
			if (type != SnsObjectType.MMSNS_OBJECT_TEXT && (mediaList == null || mediaList.get_Count() <= 0))
			{
				return null;
			}
			SnsInfo snsInfo = new SnsInfo();
			snsInfo.strObjectID = SnsInfoMgr.allocObjectID();
			snsInfo.strNickName = AccountMgr.getCurAccount().strNickName;
			snsInfo.strUserName = AccountMgr.getCurAccount().strUsrName;
			snsInfo.nStatus = 1;
			snsInfo.nObjectStyle = (int)type;
			uint nCreateTime = (uint)Util.getNowSeconds();
			snsInfo.nCreateTime = nCreateTime;
			if (userNameList != null && userNameList.get_Count() > 0)
			{
				snsInfo.nWithUserCount = userNameList.get_Count();
				if (userNameList != null && userNameList.get_Count() > 0)
				{
					SnsCommentList snsCommentList = new SnsCommentList();
					snsCommentList.list = new List<SnsComment>();
					using (List<string>.Enumerator enumerator = userNameList.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							string current = enumerator.get_Current();
							if (!string.IsNullOrEmpty(current))
							{
								SnsComment snsComment = new SnsComment();
								snsComment.strUserName = current;
								snsComment.nCreateTime = nCreateTime;
								snsCommentList.list.Add(snsComment);
							}
						}
					}
					snsInfo.withList = snsCommentList;
				}
			}
			SnsGroupList snsGroupList = new SnsGroupList();
			if (groupIdList != null && groupIdList.get_Count() != 0)
			{
				snsGroupList.nCount = groupIdList.get_Count();
				snsGroupList.list.AddRange(groupIdList);
			}
			else
			{
				snsGroupList.nCount = 0;
			}
			snsInfo.groupList = snsGroupList;
			TimeLineObject timeLineObject = new TimeLineObject();
			timeLineObject.strContentDesc = words;
			timeLineObject.nPrivate = Privacy;
			timeLineObject.nCreateTime = nCreateTime;
			timeLineObject.strNickName = snsInfo.strNickName;
			timeLineObject.strUsername = snsInfo.strUserName;
			if (location != null)
			{
				timeLineObject.tloLocation_0 = location;
			}
			timeLineObject.content = new ContentObject();
			timeLineObject.content.nStyle = (int)type;
			if (type != SnsObjectType.MMSNS_OBJECT_TEXT)
			{
				timeLineObject.content.mediaList = mediaList;
			}
			else
			{
				snsInfo.nStatus = 2;
			}
			SnsInfoMgr.setTimeLine(snsInfo, timeLineObject);
			Util.ByteArrayToString(snsInfo.bytesObjectDesc);
			StorageMgr.snsInfo.method_3(snsInfo);
			return snsInfo;
		}
		public static SnsInfo createShareSnsObject(ContentObject contentObj, string words, SnsObjectType type = SnsObjectType.MMSNS_OBJECT_FEED)
		{
			if (contentObj == null)
			{
				return null;
			}
			SnsInfo snsInfo = new SnsInfo();
			snsInfo.strNickName = AccountMgr.getCurAccount().strNickName;
			snsInfo.strUserName = AccountMgr.getCurAccount().strUsrName;
			snsInfo.nStatus = 2;
			snsInfo.nObjectStyle = (int)type;
			uint nCreateTime = (uint)Util.getNowSeconds();
			snsInfo.nCreateTime = nCreateTime;
			SnsInfoMgr.setTimeLine(snsInfo, new TimeLineObject
			{
				strContentDesc = words,
				nPrivate = 0,
				nCreateTime = nCreateTime,
				strNickName = snsInfo.strNickName,
				strUsername = snsInfo.strUserName,
				content = new ContentObject(),
				content = 
				{
					nStyle = (int)type,
					mediaList = contentObj.mediaList,
					strContentUrl = contentObj.strContentUrl,
					strTitle = contentObj.strTitle,
					strDescription = contentObj.strDescription
				}
			});
			Util.ByteArrayToString(snsInfo.bytesObjectDesc);
			return snsInfo;
		}
		public static bool resumeUploadAndPost()
		{
			List<SnsInfo> needResumeList = SnsInfoMgr.getNeedResumeList();
			if (needResumeList != null && needResumeList.get_Count() > 0)
			{
				using (List<SnsInfo>.Enumerator enumerator = needResumeList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						SnsInfo current = enumerator.get_Current();
						if (current != null)
						{
							TimeLineObject timeLine = SnsInfoMgr.getTimeLine(current);
							if (timeLine != null)
							{
								SnsPostContext snsPostContext = new SnsPostContext();
								SnsTrans byLocalID = StorageMgr.snsTrans.getByLocalID(current.nLocalID);
								if (current.nStatus == 1)
								{
									if (byLocalID == null)
									{
										snsPostContext.strContent = timeLine.strContentDesc;
										snsPostContext.localSnsObject = current;
										snsPostContext.sync2WeiboFlag = 0u;
										snsPostContext.privacyFlag = timeLine.nPrivate;
										snsPostContext.bgImgType = BgImgType.MMSNS_SETBGIMG_SELFPIC;
										snsPostContext.objectType = timeLine.content.nStyle;
										snsPostContext.strClientID = MD5Core.GetHashString(Util.getNowMilliseconds() + " ");
										if (snsPostContext.objectType == 2)
										{
											NetSceneSnsPost netSceneSnsPost = new NetSceneSnsPost();
											netSceneSnsPost.doScene(snsPostContext);
											return true;
										}
										if (!snsPostContext.initSnsTransContext())
										{
											Log.smethod_1("SnsPostService", "initSnsTransContext fail!");
										}
										else
										{
											SnsPostContextMgr.getInstance().putToTail(snsPostContext);
											SnsPostService.checkReadyContextDispatcher();
										}
									}
									else
									{
										if (byLocalID.snsImgTransList != null)
										{
											if (SnsPostService.isSnsTranHasErrorImg(byLocalID.snsImgTransList))
											{
												current.nStatus = 4;
												StorageMgr.snsInfo.update(current);
												Log.smethod_1("SnsPostService", "obj.nObjectID = " + current.nObjectID + " SnsTran Has ErrorImg");
											}
											else
											{
												snsPostContext.strContent = timeLine.strContentDesc;
												snsPostContext.localSnsObject = current;
												snsPostContext.sync2WeiboFlag = 0u;
												snsPostContext.privacyFlag = timeLine.nPrivate;
												snsPostContext.bgImgType = BgImgType.MMSNS_SETBGIMG_SELFPIC;
												snsPostContext.mSnsTrans = byLocalID;
												SnsPostContextMgr.getInstance().putToTail(snsPostContext);
												SnsPostService.checkReadyContextDispatcher();
											}
										}
									}
								}
								else
								{
									if (current.nStatus == 2)
									{
										if (byLocalID == null)
										{
											if (SnsInfoMgr.getTimeLine(current).content.nStyle != 2)
											{
												continue;
											}
											snsPostContext.objectType = 2;
										}
										else
										{
											snsPostContext.mSnsTrans = byLocalID;
											snsPostContext.strClientID = byLocalID.strClientID;
										}
										snsPostContext.strContent = timeLine.strContentDesc;
										snsPostContext.localSnsObject = current;
										snsPostContext.sync2WeiboFlag = 0u;
										snsPostContext.privacyFlag = timeLine.nPrivate;
										snsPostContext.bgImgType = BgImgType.MMSNS_SETBGIMG_SELFPIC;
										NetSceneSnsPost netSceneSnsPost2 = new NetSceneSnsPost();
										netSceneSnsPost2.doScene(snsPostContext);
									}
								}
							}
						}
					}
				}
				return true;
			}
			return true;
		}
		public static bool resendAndPost(int objectLocalID)
		{
			SnsInfo snsInfo = StorageMgr.snsInfo.method_1(objectLocalID);
			if (snsInfo == null)
			{
				Log.smethod_1("SnsPostService", "objectLocalID = " + objectLocalID + " the snsInfo is not exist");
				return false;
			}
			if (snsInfo.nStatus != 4)
			{
				Log.smethod_1("SnsPostService", "objectLocalID = " + objectLocalID + " the snsInfo status is not error");
				return false;
			}
			snsInfo.nStatus = 1;
			TimeLineObject timeLine = SnsInfoMgr.getTimeLine(snsInfo);
			if (timeLine == null)
			{
				return false;
			}
			SnsPostContext snsPostContext = new SnsPostContext();
			SnsTrans byLocalID = StorageMgr.snsTrans.getByLocalID(snsInfo.nLocalID);
			if (byLocalID != null && byLocalID.snsImgTransList != null)
			{
				using (List<SnsMediaTrans>.Enumerator enumerator = byLocalID.snsImgTransList.list.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						SnsMediaTrans current = enumerator.get_Current();
						if (current != null && current.nStatus == 4)
						{
							current.nStatus = 0;
							current.nRetryTimes = 0;
						}
					}
				}
				StorageMgr.snsInfo.update(snsInfo);
				byLocalID.snsImgTransList = byLocalID.snsImgTransList;
				StorageMgr.snsTrans.update(byLocalID);
				snsPostContext.strContent = timeLine.strContentDesc;
				snsPostContext.localSnsObject = snsInfo;
				snsPostContext.sync2WeiboFlag = 0u;
				snsPostContext.privacyFlag = timeLine.nPrivate;
				snsPostContext.bgImgType = BgImgType.MMSNS_SETBGIMG_SELFPIC;
				snsPostContext.mSnsTrans = byLocalID;
				SnsPostContextMgr.getInstance().putToHead(snsPostContext);
				SnsPostService.checkReadyContextDispatcher();
				return true;
			}
			Log.smethod_1("SnsPostService", "objectLocalID = " + objectLocalID + " the trans or snsTrans.snsImgTransList is null");
			return false;
		}
		public static bool isSnsTranHasErrorImg(SnsMediaTransList snsImgTransList)
		{
			bool result;
			using (List<SnsMediaTrans>.Enumerator enumerator = snsImgTransList.list.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					SnsMediaTrans current = enumerator.get_Current();
					if (current.nStatus == 4 && current.nRetryTimes >= 1)
					{
						result = true;
						return result;
					}
				}
				return false;
			}
			return result;
		}
		public static TloMedia snsSavePhoto(Stream origStream, bool isNeedCompress = true, bool isCreateThumb = true)
		{
			string randomPath = SnsMediaStorage.getRandomPath();
			MemoryStream memoryStream = new MemoryStream();
			ImgRet imgRet = Util.compressImage(origStream, memoryStream, 960, 960, 70, 102400);
			if (imgRet == null)
			{
				return null;
			}
			SnsMediaStorage.save(randomPath, memoryStream.ToArray());
			memoryStream.Close();
			string randomPath2 = SnsMediaStorage.getRandomPath();
			if (isCreateThumb)
			{
				MemoryStream memoryStream2 = new MemoryStream();
				if (!Util.saveThumb(origStream, memoryStream2, 480, 480, 70))
				{
					return null;
				}
				SnsMediaStorage.save(randomPath2, memoryStream2.ToArray());
				memoryStream2.Close();
			}
			return new TloMedia
			{
				nType = 2,
				nUrlType = 0,
				strUrl = randomPath,
				nWidth = (float)imgRet.iWidth,
				nHeight = (float)imgRet.iHeight,
				nTotalSize = (float)((int)imgRet.nTotalLenth),
				nThumbType = 0,
				strThumb = randomPath2
			};
		}
		public static TloMedia snsSavePhotoEx(WriteableBitmap origBitmap, int int_0, bool isNeedCompress = true, bool isCreateThumb = true)
		{
			string randomPath = SnsMediaStorage.getRandomPath();
			MemoryStream memoryStream = new MemoryStream();
			ImgRet imgRet = Util.compressImageEx(origBitmap, int_0, memoryStream, 960, 960, 70, 102400);
			if (imgRet == null)
			{
				return null;
			}
			SnsMediaStorage.save(randomPath, memoryStream.ToArray());
			memoryStream.Close();
			string randomPath2 = SnsMediaStorage.getRandomPath();
			if (isCreateThumb)
			{
				MemoryStream memoryStream2 = new MemoryStream();
				if (Util.compressImageEx(origBitmap, int_0, memoryStream2, 480, 480, 70, 51200) == null)
				{
					return null;
				}
				SnsMediaStorage.save(randomPath2, memoryStream2.ToArray());
				memoryStream2.Close();
			}
			return new TloMedia
			{
				nType = 2,
				nUrlType = 0,
				strUrl = randomPath,
				nWidth = (float)imgRet.iWidth,
				nHeight = (float)imgRet.iHeight,
				nTotalSize = (float)((int)imgRet.nTotalLenth),
				nThumbType = 0,
				strThumb = randomPath2
			};
		}
		public static TloMedia snsSaveSysPictureThumb(Stream origStream, bool isNeedCompress = true)
		{
			Log.smethod_5("SnsPostService", "snsSavePhotoThumb In");
			string randomPath = SnsMediaStorage.getRandomPath();
			using (MemoryStream memoryStream = new MemoryStream())
			{
				if (!Util.saveThumb(origStream, memoryStream, 480, 480, 70))
				{
					return null;
				}
				SnsMediaStorage.save(randomPath, memoryStream.ToArray());
			}
			TloMedia tloMedia = new TloMedia();
			tloMedia.strThumb = randomPath;
			Log.smethod_5("SnsPostService", "snsSavePhotoThumb End");
			return tloMedia;
		}
		public static void snsRotateThumb(TloMedia media, int nAngle)
		{
			BitmapImage bitmapImage = ImageCacheMgr.loadFromFile(media.strThumb);
			WriteableBitmap image = new WriteableBitmap(bitmapImage);
			image = Util.rotatePicture(image, nAngle);
			Stream stream = Util.bitmapToStream(image);
			using (MemoryStream memoryStream = new MemoryStream())
			{
				stream.CopyTo(memoryStream);
				SnsMediaStorage.save(media.strThumb, memoryStream.ToArray());
			}
		}
		private static string snsSaveThumb(Stream origStream)
		{
			string randomPath = SnsMediaStorage.getRandomPath();
			MemoryStream memoryStream = new MemoryStream();
			Util.saveThumb(origStream, memoryStream, 300, 300, 90);
			SnsMediaStorage.save(randomPath, memoryStream.ToArray());
			return randomPath;
		}
		public static Stream loadImge(string fileName)
		{
			Stream result;
			try
			{
				using (SnsPostService.mCurrentIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
				{
					if (!SnsPostService.mCurrentIsolatedStorage.FileExists(fileName))
					{
						result = null;
					}
					else
					{
						IsolatedStorageFileStream isolatedStorageFileStream = SnsPostService.mCurrentIsolatedStorage.OpenFile(fileName, 3, 1);
						result = isolatedStorageFileStream;
					}
				}
			}
			catch (Exception)
			{
				result = null;
			}
			return result;
		}
		private static void checkReadyContextDispatcher()
		{
			if (SnsPostService.mTimerObject == null)
			{
				SnsPostService.mTimerObject = TimerService.addTimer(8, new EventHandler(SnsPostService.onImageContextDispatcher), 1, -1);
				SnsPostService.mTimerObject.start();
			}
			SnsPostService.setMaxSendImgCount();
		}
		public static void onImageContextDispatcher(object sender, EventArgs e)
		{
			if (SnsPostService.isBeenLogout)
			{
				Log.smethod_1("SnsPostService", "Account has been logout, close dispatcher timer.");
				SnsPostContextMgr.getInstance().clearnAll();
				SnsPostService.mTimerObject.stop();
				SnsPostService.mTimerObject = null;
				return;
			}
			SnsPostContextMgr.getInstance().clearnFinishedContext();
			if (SnsPostContextMgr.getInstance().countRunningContext() >= 5)
			{
				return;
			}
			SnsPostContext firstContextNeedHandle = SnsPostContextMgr.getInstance().getFirstContextNeedHandle();
			if (firstContextNeedHandle == null)
			{
				if (SnsPostContextMgr.getInstance().countRunningContext() == 0)
				{
					Log.smethod_4("SnsPostService", "all ready, close dispatcher timer. ");
					SnsPostService.mTimerObject.stop();
					SnsPostService.mTimerObject = null;
				}
				return;
			}
			if (firstContextNeedHandle.localSnsObject == null)
			{
				Log.smethod_1("SnsPostService", "postContext.localSnsObject == null");
				firstContextNeedHandle.mSnsObjectStatus = 5;
				return;
			}
			if (firstContextNeedHandle.mSnsTrans == null)
			{
				Log.smethod_1("SnsPostService", "postContext.mSnsTrans is null!");
				firstContextNeedHandle.mSnsObjectStatus = 5;
				return;
			}
			int count = firstContextNeedHandle.mSnsTrans.snsImgTransList.list.get_Count();
			if (count <= 0 || count > 9)
			{
				Log.smethod_1("SnsPostService", "image num error, num = " + count);
			}
			firstContextNeedHandle.mSnsObjectStatus = 1;
			int num = 0;
			int num2 = (count > SnsPostService.mMaxCountOnce) ? SnsPostService.mMaxCountOnce : count;
			for (int i = 0; i < num2; i++)
			{
				SnsMediaTrans snsMediaTrans = firstContextNeedHandle.tryGetNeedSendSnsTranImg();
				if (snsMediaTrans != null)
				{
					NetSceneSnsUpload netSceneSnsUpload = new NetSceneSnsUpload();
					NetSceneSnsUpload expr_13A = netSceneSnsUpload;
					expr_13A.mOnSceneFinished = (onSceneFinishedUploadDelegate)Delegate.Combine(expr_13A.mOnSceneFinished, new onSceneFinishedUploadDelegate(SnsPostService.oneSnsUploadSceneFinished));
					if (!netSceneSnsUpload.doScene(firstContextNeedHandle, snsMediaTrans))
					{
						Log.smethod_1("SnsPostService", "three sceneSnsUpload.doScene fail!");
						snsMediaTrans.nStatus = 4;
						snsMediaTrans.nRetryTimes++;
						firstContextNeedHandle.mSnsObjectStatus = 5;
						firstContextNeedHandle.localSnsObject.nStatus = 4;
						StorageMgr.snsInfo.update(firstContextNeedHandle.localSnsObject);
						return;
					}
					num++;
				}
				else
				{
					int num3 = firstContextNeedHandle.isAllTransSuccess();
					if (num3 == 2)
					{
						Log.smethod_5("SnsPostService", "all picture send success!");
						if (!firstContextNeedHandle.isTimeLineImgSuccess())
						{
							Log.smethod_1("SnsPostService", "trans all success but timeline img url is not correct, fix it!");
							firstContextNeedHandle.fixTimelineImgList();
						}
						firstContextNeedHandle.mSnsObjectStatus = 2;
						firstContextNeedHandle.mSnsTrans.nObjectstatus = firstContextNeedHandle.mSnsObjectStatus;
						firstContextNeedHandle.localSnsObject.nStatus = 2;
						firstContextNeedHandle.setSnsInfoByTransContext();
						StorageMgr.snsTrans.update(firstContextNeedHandle.mSnsTrans);
						StorageMgr.snsInfo.update(firstContextNeedHandle.localSnsObject);
						NetSceneSnsPost netSceneSnsPost = new NetSceneSnsPost();
						netSceneSnsPost.doScene(firstContextNeedHandle);
					}
					else
					{
						if (num3 == 1)
						{
							firstContextNeedHandle.mSnsObjectStatus = 4;
							firstContextNeedHandle.mSnsTrans.nObjectstatus = firstContextNeedHandle.mSnsObjectStatus;
							firstContextNeedHandle.localSnsObject.nStatus = 4;
							StorageMgr.snsTrans.method_2(firstContextNeedHandle.mSnsTrans);
							Log.smethod_5("SnsPostService", "update err status_2 context.localSnsObject.nLocalID = " + firstContextNeedHandle.localSnsObject.nLocalID);
							StorageMgr.snsInfo.update(firstContextNeedHandle.localSnsObject);
						}
					}
				}
			}
			Log.smethod_5("SnsPostService", "firstSendCount = " + num);
			if (num <= 0)
			{
				Log.smethod_1("SnsPostService", "No picture need send in snsObject");
				firstContextNeedHandle.mSnsObjectStatus = 5;
			}
		}
		public static void oneSnsUploadSceneFinished(SnsPostContext context, SnsMediaTrans imgTrans, NetSceneSnsUpload scene, bool isSuccess)
		{
			SnsMediaTrans snsMediaTrans = context.tryGetNeedSendSnsTranImg();
			if (snsMediaTrans != null)
			{
				scene.doScene(context, snsMediaTrans);
				return;
			}
			int num = context.isAllTransSuccess();
			if (num == 2)
			{
				Log.smethod_5("SnsPostService", "all picture send success!");
				if (!context.isTimeLineImgSuccess())
				{
					Log.smethod_1("SnsPostService", "trans all success but timeline img url is not correct, fix it!");
					context.fixTimelineImgList();
				}
				context.mSnsObjectStatus = 2;
				context.mSnsTrans.nObjectstatus = context.mSnsObjectStatus;
				context.localSnsObject.nStatus = 2;
				context.setSnsInfoByTransContext();
				StorageMgr.snsTrans.update(context.mSnsTrans);
				StorageMgr.snsInfo.update(context.localSnsObject);
				NetSceneSnsPost netSceneSnsPost = new NetSceneSnsPost();
				netSceneSnsPost.doScene(context);
				return;
			}
			if (num == 1)
			{
				context.mSnsObjectStatus = 4;
				context.mSnsTrans.nObjectstatus = context.mSnsObjectStatus;
				context.localSnsObject.nStatus = 4;
				StorageMgr.snsTrans.method_2(context.mSnsTrans);
				Log.smethod_5("SnsPostService", "update err status_3 context.localSnsObject.nLocalID = " + context.localSnsObject.nLocalID);
				StorageMgr.snsInfo.update(context.localSnsObject);
				return;
			}
			if (context.isTimeToEndErrorUpload())
			{
				Log.smethod_5("SnsPostService", "Sns post fail because picture upload fail");
				context.mSnsObjectStatus = 4;
				context.mSnsTrans.nObjectstatus = context.mSnsObjectStatus;
				context.localSnsObject.nStatus = 4;
				StorageMgr.snsTrans.update(context.mSnsTrans);
				Log.smethod_5("SnsPostService", "update err status_4 context.localSnsObject.nLocalID = " + context.localSnsObject.nLocalID);
				StorageMgr.snsInfo.update(context.localSnsObject);
			}
		}
		public static void setMaxSendImgCount()
		{
			if (NetworkDeviceWatcher.isCurrentCell2G())
			{
				SnsPostService.mMaxCountOnce = 1;
				return;
			}
			if (NetworkDeviceWatcher.isCurrentCell3G())
			{
				SnsPostService.mMaxCountOnce = 3;
				return;
			}
			SnsPostService.mMaxCountOnce = 5;
		}
		public static uint getSyncToBlogFlag(uint syncFlag = 0u)
		{
			return syncFlag |= 1u;
		}
		public static uint getSyncToFacebookFlag(uint syncFlag = 0u)
		{
			return syncFlag |= 2u;
		}
		public static void testPost()
		{
		}
		public static void testPostTextObj(int count)
		{
			string text = DateTime.get_Now().ToString();
			for (int i = 0; i < count; i++)
			{
				int num = i + 1;
				string words = string.Concat(new object[]
				{
					text,
					"这次共发\"",
					count,
					"\"条,本条是第\"",
					num,
					"\"条"
				});
				SnsPostService.UploadAndPost(null, null, null, words, 0u, 0, SnsObjectType.MMSNS_OBJECT_TEXT, BgImgType.MMSNS_SETBGIMG_SELFPIC, null);
			}
		}
	}
}
